//
//  NetWork.m
//  CI
//
//  Created by tongbu_jinzhongjun on 14-10-20.
//  Copyright (c) 2014年 tongbu_jinzhongjun. All rights reserved.
//

#import "NetWork.h"

@implementation NetWork

+(AFHTTPRequestOperationManager*) manager {
//    unsigned long encode = CFStringConvertEncodingToNSStringEncoding(0x0632);
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    AFHTTPRequestSerializer *request_serializer = [AFHTTPRequestSerializer serializer];
    request_serializer.stringEncoding =  CFStringConvertEncodingToNSStringEncoding(0x0632);
    
    AFHTTPResponseSerializer *response_serializer = [AFHTTPResponseSerializer serializer];
    response_serializer.stringEncoding =  CFStringConvertEncodingToNSStringEncoding(0x0632);
    
    manager.responseSerializer = response_serializer;
    manager.requestSerializer = request_serializer;
    
    return manager;
}

+(void)post:(NSString*) urlString parameters:(id)parameter  success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
    failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
    
    [[[self class] manager] POST:urlString
                      parameters:parameter
                         success:^(AFHTTPRequestOperation *operation, id responseObject) {
                             //对返回结果进行转码
                             NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:CFStringConvertEncodingToNSStringEncoding(0x0632)];
                             responseObject = [responseString dataUsingEncoding:NSUTF8StringEncoding];
                             success(operation,responseObject);
                         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                             failure(operation,error);
                         }];
}

@end
